package com.bs.service.impl;

import com.bs.bean.Bills;
import com.bs.dao.BillsMapper;
import com.bs.service.BillsService;
import com.bs.util.PageHelperEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BillsServiceImpl implements BillsService {
    @Resource
    private BillsMapper billsMapper;

    @Override
    public PageInfo<Bills> getBills(int index, int typeId, String fromDate, String toDate) {
        Map args = new HashMap();
        args.put("typeId", typeId);
        args.put("fromDate", fromDate);
        args.put("toDate", toDate);
        PageHelper.startPage(index, PageHelperEnum.DEFAULT_PAGE_SIZE.getPageSize());
        List<Bills> bills = billsMapper.getBills(args);
        PageInfo<Bills> billsPageInfo = new PageInfo<>(bills);
        return billsPageInfo;
    }

    @Override
    public int insert(Bills bills) {
        return billsMapper.insert(bills);
    }

    @Override
    public Bills selectByPrimaryKey(Integer id) {
        return billsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(Bills bills) {
        return billsMapper.updateByPrimaryKey(bills);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return billsMapper.deleteByPrimaryKey(id);
    }
}
